package org.example.demo1startjava17.filter;


import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

/**
 * 配置方式3
 * 1.实现Filter接口
 *
 */
@Slf4j
public class MyFilter4 implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
//        log.info("MyFilter 初始化了");
        System.err.println("MyFilter4 初始化了");
        Filter.super.init(filterConfig);
//        System.err.println(filterConfig.getFilterName());
//        System.err.println(JSON.toJSONString(filterConfig.getServletContext()));
//        System.err.println(JSON.toJSONString(filterConfig.getInitParameterNames()));
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
//        log.info("MyFilter 执行了 {}", httpServletRequest.getRequestURI());
        System.err.println("MyFilter4 执行了 " + httpServletRequest.getRequestURI());
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
